layui.use(['laydate', 'laypage', 'layer', 'table', 'upload', 'element','form'], function(){
	  var laydate = layui.laydate //日期
	  ,laypage = layui.laypage //分页
	  layer = layui.layer //弹层
	  ,table = layui.table //表格
	  ,upload = layui.upload //上传
	  ,element = layui.element //元素操作
	  ,form = layui.form; //form表单
	 
	  
	  //监听Tab切换
	  element.on('tab(demo)', function(data){
	    layer.msg('切换了：'+ this.innerHTML);
	    console.log(data);
	  });
	  
	//日期选择框渲染
	  laydate.render({
		    elem: '#frTimeMin'
		    ,theme: 'molv'
		    ,type: 'datetime'
		  });
	  laydate.render({
		    elem: '#frTimeMax'
		    ,theme: 'molv'
		    ,type: 'datetime'
		  });
	  
	  //调用计算总金额的方法
	  totalMoney(null);
	  
	  //执行一个 table 实例
	  table.render({
	     elem: '#FinancialRecord'
	    ,width:1064
	    ,height: 406
	    ,url: getRootPath()+'FinancialRecord/findByFsId.action' //数据接口
	    ,page: true //开启分页
	    ,method:'post'
	    ,size: 'sm'
	    ,cols: [[ //表头
	       {type:'checkbox', fixed: 'left'}
	      ,{field: 'frId', title: '财务记录ID', sort: 'true', align: 'center', width:180, fixed: 'left'}
	      ,{field: 'fsId', title: '财务ID', sort: 'true', align: 'center', width:120}
	      ,{field: 'pwId', title: '业务ID', sort: 'true', align: 'center', width:160}
	      ,{field: 'frName', title: '支出或收入', sort: 'true', align: 'center', width: 120}
	      ,{field: 'frSumprice', title: '财务记录总金额', sort: 'true', align: 'center', width:120}
	      ,{field: 'frRemark', title: '财务记录备注', sort: 'true', align: 'center', width: 120}
	      ,{field: 'sort', title: '排序', sort: 'true', align: 'center', width:120}
	      ,{field: 'isva', title: '是否有效', sort: 'true', align: 'center', width:120}
	      ,{field: 'frTimes', title: '操作时间', sort: 'true', align: 'center', width:160}
	      ,{title: '操作', align: 'center', width:160, fixed: 'right', toolbar: '#barDemo'}
	    ]]
	  	,id: 'testReload'
	  });
	  
	  form.on('select(type)', function(data){
		 table.reload('testReload',{
			 page: {
	  			    curr: 1 //重新从第 1 页开始
  			}
  			,where:{
  				frName:data.value
  			}
		 });
		 var data = {"frName":data.value};
	  	 totalMoney(data);
	 });   
	  
	  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
		  var data = obj.data; //获得当前行数据
		  var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		 
		  if(layEvent === 'ck'){ //查看
			var pwId = data.pwId;
			var frType = data.frType;
			//alert("pwId:"+pwId+"  frType:"+frType);
			var url = "";
			if(frType == "1"){
				url = "ZgsSellDetailShowList.html?soId="+pwId;
			}else if(frType == "2"){
				url = "ZgsSellDetailShowList.html?soId="+pwId;
			}else if(frType == "3"){
				url = "ZgsSellDetailShowList.html?soId="+pwId;
			}else if(frType == "4"){
				url = "ZgsSellDetailShowList.html?soId="+pwId;
			}else if(frType == "5"){
				url = "ZgsSellDetailShowList.html?soId="+pwId;
			}
			layer.open({
				  type: 2,
				  title: '财务记录详情',
				  area : ['80%' , '85%'],//弹出框大小
				  shift:1,//弹出框动画效果
				  content: url //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
				}); 
		  }
		});
	  
	  	var $ = layui.$;
	  	$("#search").click(function(){
	  		//表单序列化
	  		var form = $("form").serializeArray();
	  		
	  		var data = {"frName":form[0].value,"frSumPriceMin":form[1].value,"frSumPriceMax":form[2].value,"frTimeMin":form[3].value,"frTimeMax":form[4].value};
	  		totalMoney(data);
	  		
	  		table.reload('testReload',{
	  			page: {
	  			    curr: 1 //重新从第 1 页开始
	  			}
	  			,where:{
	  				frName:form[0].value,
	  				frSumPriceMin:form[1].value,
	  				frSumPriceMax:form[2].value,
	  				frTimeMin:form[3].value,
	  				frTimeMax:form[4].value
	  			}
	  		});
	  	});
	  
	});
//限制数字的输入
function clearNoNum(obj){ 
    obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
    obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的  
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数  
    if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额 
        obj.value= parseFloat(obj.value); 
    }
    if(obj.value.indexOf(".")==0){//第一个字符不能为.
    	 obj.value="";
    }
}
//限制最大总金额不能小于最小总金额
function minMoneyNoMaxMoney(obj){
	var frSumPriceMin = $("#frSumPriceMin").val()-0;
	var frSumPriceMax = $(obj).val()-0;
	if(frSumPriceMax < frSumPriceMin){
		$(obj).val("");
		$(obj).attr("placeholder","最大总金额不能低于最小总金额");
	}
}
//计算总金额包括根据条件查询后的总金额
function totalMoney(data){
	var url = getRootPath()+"FinancialRecord/countTotalMoney.action?fsId=1";
	$.ajax({
		url:url,
		data:data,
		success:function(msg){
			$("#totalMoney").val(msg);
		}
	});
}